package com.op.studyingliteapp.sender;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.widget.Toast;

import java.lang.*;

/**
 * Created by Genji on 2015/7/28. 监听wifi连接是否断开
 */
public class ConnectionChangeReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo wifiInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        if (wifiInfo == null) {
            Runtime.getContext().close();
            Runtime.setContext(null);
            Runtime.pause();
            Runtime.refreshStatus();
            Toast.makeText(context, "接受端已经断开", Toast.LENGTH_LONG).show();
        }

    }

}
